package com.tz.fruit.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.io.Serializable;

import javax.persistence.*;

/**
 * 商品图片实体类
 */
@Entity
@Table(name="FRUIT_IMAGE")
@JsonIgnoreProperties(value = {"comment"})//双向关联，避免死循环。
public class Image implements Serializable{
	private Long imageId;//图片ID

	private String imgUrl;//图片url

	private String info;//图片描述

	private Product product;//所属商品

	private Comment comment;//所属评论

	private Integer mark;//是否属于详情


	@Column
	public Integer getMark() {
		return mark;
	}

	public void setMark(Integer mark) {
		this.mark = mark;
	}

	public Image() {
	}

	public Image(String imgUrl, String info, Product product) {
		super();
		this.imgUrl = imgUrl;
		this.info = info;
		this.product = product;
	}
	
	public Image(String imgUrl, String info, Comment comment) {
		super();
		this.imgUrl = imgUrl;
		this.info = info;
		this.comment = comment;
	}

	@Id
	@GeneratedValue
	public Long getImageId() {
		return imageId;
	}

	public void setImageId(Long imageId) {
		this.imageId = imageId;
	}

	public String getImgUrl() {
		return imgUrl;
	}

	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}
	
	@ManyToOne
	@JoinColumn(name="pid")
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}
	
	@ManyToOne
	@JoinColumn(name="commentId")
	public Comment getComment() {
		return comment;
	}

	public void setComment(Comment comment) {
		this.comment = comment;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Image other = (Image) obj;
		if (imageId == null) {
			if (other.imageId != null)
				return false;
		} else if (!imageId.equals(other.imageId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Image [imageId=" + imageId + ", imgUrl=" + imgUrl + ", info=" + info + "]";
	}
	
}
